﻿using System;
using System.Web;
using uForum.Businesslogic;
using uForum.Businesslogic.Services;
using uForum.Configuration;

namespace uForum.usercontrols.uForum
{
    public partial class NewComment : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            AuthorizationService auth = new AuthorizationService();
            Rights rights = auth.GetRights(ForumId);
            if (!rights.CanPost)
            {
                mvwControl.SetActiveView(vwLogin);
            }
        }
        protected int ForumId
        {
            get { return umbraco.presentation.nodeFactory.Node.GetCurrent().Id; }
        }

        protected void create_Click(object sender, EventArgs e)
        {
            PostingService service = new PostingService();
            int topicId = Convert.ToInt32(HttpContext.Current.Items[ContentProperties.TopicIdHttpKey]);
            string body = commentBody.Text;
            try
            {
                string redirUrl = service.NewComment(topicId, 10, body);
                Response.Redirect(redirUrl);
            }
            catch (ArgumentException ex)
            {
                litErrorText.Text = ex.Message;
                mvwControl.SetActiveView(vwError);
            }
        }
    }
}